package com.linkdood.app.component;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.quartz.SchedulerListener;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.springframework.stereotype.Component;

/**
 * 调度器监听器，用以打印日志
 *
 * @author hycao
 */
@Slf4j
@Component
public class SimpleSchedulerListener implements SchedulerListener {

    @Override
    public void jobScheduled(Trigger trigger) {
        String jobName = trigger.getJobKey().getName();
        log.debug("{} has been scheduled", jobName);
    }

    @Override
    public void jobUnscheduled(TriggerKey triggerKey) {
        log.debug("{} is being unscheduled", triggerKey);
    }

    @Override
    public void triggerFinalized(Trigger trigger) {
        log.debug("Trigger is finished for {}", trigger.getJobKey().getName());
    }

    @Override
    public void triggerPaused(TriggerKey triggerKey) {
        log.debug("{} is being paused", triggerKey);
    }

    @Override
    public void triggersPaused(String triggerGroup) {
        log.debug("trigger group {} is being paused", triggerGroup);
    }

    @Override
    public void triggerResumed(TriggerKey triggerKey) {
        log.debug("{} is being resumed", triggerKey);
    }

    @Override
    public void triggersResumed(String triggerGroup) {
        log.debug("trigger group {} is being resumed", triggerGroup);
    }

    @Override
    public void jobAdded(JobDetail jobDetail) {
        log.debug("{} is added", jobDetail.getKey());
    }

    @Override
    public void jobDeleted(JobKey jobKey) {
        log.debug("{} is deleted", jobKey);
    }

    @Override
    public void jobPaused(JobKey jobKey) {
        log.debug("{} is paused", jobKey);

    }

    @Override
    public void jobsPaused(String jobGroup) {
        log.debug("job group {} is paused", jobGroup);
    }

    @Override
    public void jobResumed(JobKey jobKey) {
        log.debug("{} is resumed", jobKey);
    }

    @Override
    public void jobsResumed(String jobGroup) {
        log.debug("job group {} is resumed", jobGroup);
    }

    @Override
    public void schedulerError(String msg, SchedulerException cause) {
        log.error(msg, cause.getUnderlyingException());
    }

    @Override
    public void schedulerInStandbyMode() {
        log.debug("scheduler is in standby mode");
    }

    @Override
    public void schedulerStarted() {
        log.debug("scheduler has been started");
    }

    @Override
    public void schedulerStarting() {
        log.debug("scheduler is being started");
    }

    @Override
    public void schedulerShutdown() {
        log.debug("scheduler has been shutdown");
    }

    @Override
    public void schedulerShuttingdown() {
        log.debug("scheduler is being shutdown");
    }

    @Override
    public void schedulingDataCleared() {
        log.debug("scheduler has cleared all data");
    }
}